home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9505 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: sunrise.gv.ssi1.com!news
  2. From: Mike Palmer <Mike.Palmer@tus.ssi1.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Will Java kill C++?
  5. Date: 2 Mar 1996 04:54:27 GMT
  6. Organization: Silicon Systems, Inc.
  7. Message-ID: <4h8ka3$4o8@atlas.tus.ssi1.com>
  8. References: <3134D499.653E@ix.netcom.com> <313613B2.136E@ksopk.sprint.com> <4h554t$9jk@netline-fddi.jpl.nasa.gov>
  9. NNTP-Posting-Host: pc259u.tus.ssi1.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
  14.  
  15. madler@alumni.caltech.edu wrote:
  16. >In <313613B2.136E@ksopk.sprint.com> Eric Williams wrote:
  17. >" Overloaded operators are just methods... you can implement identical
  18. >" functionality using "regular" methods.
  19. >
  20. >No you can't, since operators have varying levels of precedence, methods 
  21. >don't.  An arithmetic expression with just a few operations written using 
  22. >methods is completely unreadable.  It looks like LISP.
  23. >
  24. >mark
  25. >
  26.  
  27. I think the point was that you don't need overloaded operators to, say,
  28. add two complex numbers together, multiply the result by a third, and
  29. so on. The programmer obviously has to consider the correct order of
  30. execution, and so on. 
  31.  
  32. You are absolutely correct, though, in that the result is unreadable.
  33. I have overloaded operators for many of my classes, especially strings 
  34. and matrices, just because of the notational (and readable) 
  35. convenience.
  36.  
  37. Although I could use overloaded operators to create a language that 
  38. only I understand, if they are used in an intelligent and judicious
  39. manner, they can enhance the readability of code significantly, even 
  40. for someone who doesn't know beans about your classes.
  41.  
  42. For example, when I show the code fragment:
  43.  
  44.     Matrix A, B, C;
  45.     ...
  46.     A = A * B + C;
  47.  
  48. to most programmers, they can immediately tell what is happening, 
  49. whereas
  50.  
  51.     Matrix A, B, C;
  52.  
  53.     Matmult(A,B,A);
  54.     MatAdd(A,C,A);
  55.  
  56. wouldn't be nearly so obvious, even though the function is the same.
  57.  
  58. So, my point is that when used intelligently, overloaded operators can
  59. be a useful tool, and can be used to create code that others can read
  60. and understand better than if you didn't have them.
  61.  
  62. -- Mike --
  63.  
  64.